import matplotlib.pyplot as plt#画图工具
from mpl_toolkits.mplot3d import Axes3D
from sklearn import datasets
from sklearn.discriminant_analysis import LinearDiscriminantAnalysis as LDA

data=datasets.load_wine()
X=data['data']
y=data['target']

lda = LDA(n_components=2)
X_r =lda.fit(X,y).transform(X)
ax = plt.figure()
for c, i, target_name in zip("rgb", [0, 1, 2], data.target_names):
    plt.scatter(X_r[y == i, 0], X_r[y == i, 1], c=c, label=target_name)
plt.xlabel('Dimension1')
plt.ylabel('Dimension2')
plt.title("LDA")
plt.legend()
plt.show()
